package ua.kharkov.knure.dereza.summarytask4.command;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import ua.kharkov.knure.dereza.summarytask4.core.Constants;
import ua.kharkov.knure.dereza.summarytask4.db.bean.ClientBean;

/**
 * View settings of clients and admin
 * 
 * @author dereza
 *
 */
public class ViewSettingsCommand extends Command {

	private static final long serialVersionUID = -2612149634270646008L;

	private static final Logger log = Logger
			.getLogger(ViewSettingsCommand.class);

	@Override
	public String execute(HttpServletRequest req, HttpServletResponse res) {
		log.debug("Command starts");

		// gets client's session
		HttpSession session = req.getSession(false);

		// gets ClientBean from session
		ClientBean clientBean = (ClientBean) session.getAttribute("clientbean");
		log.trace("Got clientbean  from session --> " + clientBean);

		// if clientBean == null forward to login page
		if (clientBean == null) {
			String forward = Constants.COMMAND_LOGOUT;
			return forward;
		}
		
		String forward = Constants.PAGE_SETTINGS;
		log.debug("Command finished");
		return forward;
	}

	@Override
	public String toString() {
		return "ViewSettingsCommand";
	}
}